<?php

use common\components\tools\Html;
use yii\widgets\ActiveForm;
use kartik\select2\Select2;
use dosamigos\selectize\SelectizeTextInput;
use kartik\widgets\FileInput;

/* @var $this yii\web\View */
/* @var $model admin\modules\docu\models\Docu */
/* @var $form yii\widgets\ActiveForm */
?>

<div class="docu-form">

    <?php $form = ActiveForm::begin(['options' => ['enctype' => 'multipart/form-data']]); ?>

    <?= $form->field($model, 'title')->textInput(['maxlength' => true]) ?>

    <?= $form->field($model, 'type')->widget(Select2::class, [
        'data' => $model::getTypes(),
    ]) ?>

    <?= $form->field($model, 'status')->widget(Select2::class, [
        'data' => $model::getStatus(),
    ]) ?>

    <?php $preview = $model->pre_logo?Html::img($model->pre_logo, ['class' => "img-responsive"]):Html::imgPh(900, 300); ?>
    <?= $form->field($model, 'pre_logo')->widget(FileInput::class, [
        'options' => [
            'accept' => 'image/*',
            'multiple' => false,
        ],
        'pluginOptions' => [
            'showUpload' => false,
            'initialPreview' => $preview,
        ],
        'pluginEvents' => [
            // 上传成功后的回调方法，需要的可查看data后再做具体操作，一般不需要设置
            "fileuploaded" => "function (event, data, id, index) {}",
        ],
    ])->hint("建议图片高度300,建议图片高度不超过400") ?>

    <?= $form->field($model, 'desc')->textInput(['maxlength' => true]) ?>

    <?php
    //    echo $form->field($model, 'body')->widget(\froala\froalaeditor\FroalaEditorWidget::class, []);
    //    echo $form->field($model, 'body')->widget(\yii\redactor\widgets\Redactor::class, []);
    //    echo $form->field($model, 'body')->widget(\marqu3s\summernote\Summernote::class, []);
    //    echo $form->field($model, 'body')->widget(\mihaildev\ckeditor\CKEditor::class, []);
    //    echo $form->field($model, 'body')->widget(\borales\medium\Widget::class, []);
    //    echo $form->field($model, 'body')->widget(\artkost\yii2\trumbowyg\Trumbowyg::class, []);
    //    echo $form->field($model, 'body')->widget(\yii2jodit\JoditWidget::class, []);
    //    echo $form->field($model, 'body')->widget(\heyanlong\kindeditor\KindEditor::class, []);
    echo $form->field($model, 'contents')->widget(\kriss\wangEditor\WangEditorWidget::class);
    //    echo $form->field($model, 'body')->widget(\common\members\wodrow\widgets\ueditor\Ueditor::class, []);
    //    echo $form->field($model, 'body')->widget(\yii2mod\markdown\MarkdownEditor::class, []);
    ?>

    <?= $form->field($model, 'tagNames')->widget(SelectizeTextInput::class, [
        // calls an action that returns a JSON object with matched
        // tags
        'loadUrl' => \common\config\Env::getUrls()['webapi_url'] . "/public/tag-list",
        'options' => ['class' => 'form-control'],
        'clientOptions' => [
            'plugins' => ['remove_button'],
            'valueField' => 'name',
            'labelField' => 'name',
            'searchField' => ['name'],
            'create' => true,
        ],
    ]) ?>

    <?php if (!Yii::$app->request->isAjax) { ?>
        <div class="form-group">
            <?= Html::submitButton($model->isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
        </div>
    <?php } ?>

    <?php ActiveForm::end(); ?>
</div>